package com.tqz.remotecall;

import com.tqz.anno.RemoteCall;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

/**
 * <p>product对外暴露接口，以供其他服务使用服务名称进行调用
 *
 * @author tianqingzhao
 * @since 2021/7/8 12:12
 */
@RemoteCall(serviceName = "spring-cloud-alibaba", path = "/")
public interface ProductRemoteCall {

    @RequestMapping(value = "testRemoteCall", method = RequestMethod.GET)
    String test(@RequestParam("index") Integer index);
}

class test {
    public static void main(String[] args) throws NoSuchMethodException {
        Method method = ProductRemoteCall.class.getMethod("qryProductInfo2", long.class);

        RequestMapping requestMapping = method.getAnnotation(RequestMapping.class);
        System.out.println(requestMapping.path());
        System.out.println(requestMapping.value());


        Parameter[] parameters = method.getParameters();
        for (Parameter parameter : parameters) {
            printParameter(parameter);
        }

    }

    private static void printParameter(Parameter parameter) {
        // 参数名
        System.out.println("\t\t" + parameter.getName());
        // 是否在源码中隐式声明的参数名
        System.out.println("\t\t\t implicit:" + parameter.isImplicit());
        // 类文件中，是否存在参数名
        System.out.println("\t\t\t namePresent:" + parameter.isNamePresent());
        // 是否为虚构参数
        System.out.println("\t\t\t synthetic:" + parameter.isSynthetic());
        System.out.println("\t\t\t VarArgs:" + parameter.isVarArgs());
    }
}
